import { getMixin } from "./mixin";
import { omitByKeys } from "../object";

function bindAttached(self, options) {

}

function bindDetached(self, options) {

}

export function mPage(mix) {
    let explode = ['onLoad', 'unLoad'];
    let _s = {};
    _s.data = {..._s, ...omitByKeys(mix.data, explode)}
    _s = {..._s, ...omitByKeys(mix.properties, explode)};
    _s = {..._s, ...omitByKeys(mix.methods, explode)};
    _s = {..._s, ...omitByKeys(mix.exports, explode)};
    _s = {..._s, ...omitByKeys(Object.getPrototypeOf(mix), ['constructor'].concat(explode))};

    if (mix && mix.mixins) {
        mix.mixins.forEach(function (mixinkey) {
            let _mix = getMixin(mixinkey) || {};
            _s.data = {..._s, ..._mix.data};
            _s = {..._s, ..._mix.properties};
            _s = {..._s, ..._mix.methods}
        });
    }

    let def = Object.assign(
        _s,
        {
            onLoad (options = {}) {
                let self = this;
                self.$opt = options;
                bindAttached(self, ...options);
                mix.exports.onLoad && mix.exports.onLoad.apply(this, options)
            },
            unLoad (options = {}) {
                let self = this;
                bindDetached(self, ...options);
                mix.exports.unLoad && mix.exports.unLoad.apply(this, options)
            },
        }
    );

    Page(def);
}